package com.study.design.composite;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;


/**
 * @version V1.0
 * @title: Composite
 * @description: ${DESCRIPTION}
 * @author: wanghuilong
 * @date: 2019-07-29 10:39
 * @copyright: http://fingo.com.my/
 */
@Slf4j
public class Composite extends Component {
    private List<Component> children = new ArrayList<Component>();

    public Composite(String name) {
        super(name);
        log.info("addLogStart Composite InputParam: name : {} ", name);
    }

    @Override
    public void Add(Component c) {
        log.info("addLogStart Add InputParam: c : {} ", c);
        children.add(c);
    }

    @Override
    public void Remove(Component c) {
        log.info("addLogStart Remove InputParam: c : {} ", c);
        children.remove(c);
    }

    @Override
    public void Display(Integer depth) {
        log.info("addLogStart Display InputParam: depth : {} ", depth);
        System.out.println("--" + depth + "," + name);

        for (int i = 0; i < children.size(); i++) {
            Component component = children.get(i);
            component.Display(depth + 2);
        }
    }
}
